package Demo;

public class Demo6 {
    private static boolean flag = false;
    public static void main(String[] args) {
        Thread t = new Thread(()->{
            while(!flag){
                System.out.println("线程执行中!");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("线程执行完了!");
        });
        t.start();

        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println("设置标志位,让线程执行结束");
        flag = true;
    }
}
